﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Hotel.Models.Entity;
using System.Data;
using Hotel.Classes.Helper;

namespace Hotel.Models.DataAccess
{
    public class DARoomType
    {
        //GetList : floorID = 0
        //GetDetail : floorID = ID
        public static List<RoomType> GetListRoomType(int roomTypeId)
        {
            DataTable dt;
            List<RoomType> listRoomType = new List<RoomType>();
            using (DBManager dbManager = new DBManager("stp_Get_RoomType"))
            {
                dbManager.Add("p_PK_RoomTypeId", roomTypeId);
                dbManager.Add("IsDelete", 0);
                dt = dbManager.GetDatatable();
            }
            foreach (DataRow dr in dt.Rows)
            {
                RoomType roomType = new RoomType();
                roomType.RoomTypeId = DataHelper.GetInt(dr, "Pk_RoomTypeId");
                roomType.RoomTypeName = DataHelper.Get(dr, "RoomTypeName");
                listRoomType.Add(roomType);
            }
            return listRoomType;
        }

        public static bool DeleteRoomType(int roomTypeId)
        {
            using (DBManager dbManager = new DBManager("stp_Get_RoomType"))
            {
                try
                {
                    dbManager.Add("p_PK_RoomTypeId", roomTypeId);
                    dbManager.Add("IsDelete", 1);
                    dbManager.ExecuteNonQuery();
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }

            }
        }

        //Insert : isUpdate = false
        //Update : isUpdate = true
        public static bool SaveRoomType(RoomType roomType, bool isUpdate)
        {
            using (DBManager dbManager = new DBManager("stp_Create_RoomType"))
            {
                try
                {
                    dbManager.Add("p_PK_RoomTypeID", roomType.RoomTypeId);
                    dbManager.Add("RoomTypeName", roomType.RoomTypeName);
                    dbManager.Add("IsUpdate", isUpdate);
                    dbManager.ExecuteNonQuery();
                    return true;
                }
                catch (Exception)
                {

                    return false;
                }

            }
        }
    }
}